package com.z.qyWeixin.controller;


import com.z.base.common.ResponseCode;
import com.z.base.common.Results;
import com.z.qyWeixin.dao.OrgMapper;
import com.z.qyWeixin.vo.OrgVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author z
 * @since 2022-03-29
 */
@Controller
@RequestMapping("/qyWeixin/org")
public class OrgController {

    @Resource
    private OrgMapper orgMapper;

    @GetMapping("orgList")
    public String toOrgList() {
        return "qyWeixin/orgList";
    }

    @PostMapping("getOrgList")
    @ResponseBody
    public Results getOrgList() {
        try{
            List<OrgVO> list = orgMapper.getOrgList();
            List<OrgVO> wxList = orgMapper.getWXOrgList();
            // 查找微信后台缺的机构
            for(OrgVO o : list){
                for (OrgVO wx : wxList){
                    if(o.equals(wx)){
                        break;
                    }
                }

            }
            return Results.success(list.size(), list);
        }catch (Exception e ){
            return Results.failure(ResponseCode.error.getCode(), e.getMessage());
        }
    }

    @PostMapping("getLocalNoOrgList")
    @ResponseBody
    public Results getLocalNoOrgList() {
        try{
            List<OrgVO> list = orgMapper.getWXNOTTOLocalOrgList();
            return Results.success(list.size(), list);
        }catch (Exception e ){
            return Results.failure(ResponseCode.error.getCode(), e.getMessage());
        }
    }


}
